package com.client.ryt.task.http.response;


import com.client.ryt.basic.BaseResponse;
import com.client.ryt.entity.biz.StatementEntity;
import com.client.ryt.entity.exception.JsonException;
import com.client.ryt.entity.exception.RemoteDataException;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2014/7/12.
 */
public class StatementResponse extends BaseResponse {

   List<StatementEntity> list = new ArrayList<StatementEntity>();

    public StatementResponse(){super(null);}
    public StatementResponse(JSONObject json) {
        super(json);
        try {
            if(this.getIsSuccess()){
                JSONArray msg = json.getJSONArray("msg");
                JSONObject jo;
                StatementEntity statementEntity;
                for(int i=0;i<msg.length();i++){
                    jo = msg.getJSONObject(i);
                    statementEntity = new StatementEntity();
                    statementEntity.setId(jo.getString("id"));
                    statementEntity.setAuthStatus(jo.getInt("auth_status"));
                    statementEntity.setCreateTime(jo.getString("ct"));
                    statementEntity.setTimesUsed(jo.getInt("times_used"));
                    statementEntity.setTitle(jo.getString("title"));
                    if(statementEntity.getAuthStatus() == 0) statementEntity.setAuthStatusCn("确认消费");
                    else statementEntity.setAuthStatusCn("已确认");
                    list.add(statementEntity);
                }
            }else{
                this.setBaseException(new RemoteDataException(json));
            }
        } catch (JSONException e) {
            this.setBaseException(new JsonException(e.getMessage()));
        }
    }

    public List<StatementEntity> getList() {
        return list;
    }
}
